#!/bin/csh

#**************************************************************#
#                                                              #
#  Job j280sum.bcp will sort the input file in key sequence    #
#  and load the new data to the database.                      #
#                                                              #
#**************************************************************#

set homedir  = '/home/j280sc/SCRIPTS'
cd $homedir
set sysdir   = '/home/j280sc/SYSTEM'
set fmtdir   = '/home/j280sc/TABLES'

echo ' '
echo '**=====================================================**'
echo '** j280sum.bcp:  begin execution                       **'
echo '**=====================================================**'

set server   = 'SCPROD3' 
set dbname   = 'd280db1' 
set tbname   = 't280sum'
set user     = `cut -c1-8 $sysdir/logon_id`
set pswd     = `cut -c10-18 $sysdir/logon_id`
set loadfile = '/workarea/t280.sum1.dat'
set statusdb = 'd280db1'  
set sybrel   = 'source/1002'

#**************************************************************#
# erase any existing output file                               #
#**************************************************************#

if ( -e ${tbname}.outi ) then
  rm ${tbname}.outi
endif

if ( -e ${tbname}.outs ) then
  rm ${tbname}.outs
endif

if ( -e ${tbname}.outb ) then
  rm ${tbname}.outb
endif

if ( -e ${tbname}.err  ) then
  rm ${tbname}.err 
endif


#**************************************************************#
#  load the table using bcp                                    #
#**************************************************************#

date
echo '*BCP* -----------------------------------'
echo '*BCP* Load Data to d280db1.dbo.t280sum'
echo '*BCP* -----------------------------------'
echo ' '

$SYBASE/${sybrel}/bin/bcp ${dbname}..${tbname} in ${loadfile} \
     -U$user -P$pswd -S${server} -f${fmtdir}/${tbname}.fmt \
     -A 4096 -m 1 -e ${tbname}.err > ${tbname}.outb

if ( -e ${tbname}.err ) then
  echo '*AIX*****ERROR****  BCP Error file exists'
  cat ${tbname}.err
  cat $fmtdir/${tbname}.fmt 
  exit (12)
endif
rxx $sysdir/ERROR_CK_BCP ${tbname}.outb
set rc = $status

date
if ($rc != 0) then
  echo '*AIX* ERRORS Found'
  exit ($rc)
endif


echo ' '
echo '*AIX*Successful exit - ' 
echo ' '
echo '**=====================================================**'
echo '** j280sum.bcp:  end execution                         **'
echo '**=====================================================**'

exit
